import entity.Employee;

import java.util.Optional;

public class UseOptional {
    public static void main(String[] args) {
//        Employee employee = new Employee("杰哥",28,"台湾杰哥","台湾");
        Employee employee = null;
        //Assert 检查对象是否符合条件,不符合就报错
//        Assert.checkNonNull(employee,"123");
//        String s = queryGender(employee);
        String s = queryGenderOptional(employee);
        System.out.println(s);

    }

    private static String queryGender(Employee employee){
        if(null == employee){
            return "UnKnow";
        }
        return employee.getGender();
    }

    private static String queryGenderOptional(Employee employee){
       return Optional.ofNullable(employee).map(Employee::getGender).orElse("不知道");
    }


}
